<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title></title>

 <link rel="stylesheet" type="text/css" href="<?php echo site_url(); ?>app/views/css/common.css" />
     <link rel="stylesheet" type="text/css" href="<?php echo site_url(); ?>app/views/js/themes/bootstrap/easyui.css">
  <link rel="stylesheet" type="text/css" href="<?php echo site_url(); ?>app/views/js/themes/icon.css">
   <script type="text/javascript" src="<?php echo site_url(); ?>app/views/js/jquery.min.js"></script>
  <script type="text/javascript" src="<?php echo site_url(); ?>app/views/js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="<?php echo site_url(); ?>app/views/js/locale/easyui-lang-zh_CN.js"></script>

<script>
  function add(){
    var row = $('#tt').datagrid('getSelected');
     if (row){
      $("#parent").val(row.id);
       $("#father").val(row.name);
         }else{
          $("#parent").val('-1');
          $("#father").val("无上级分类");
         }
         $('#w').dialog('open').dialog('setTitle','新增分类');
    //$('#w').window('open');
  }

function edit(){
   var row = $('#tt').datagrid('getSelected');
     if (row){
          $("#edname").val(row.name);
           $("#edid").val(row.id);
        
         }else{
           alert("you do not selected a rocord!");
         }
    $('#edit').window('open');
 }


  function del(){
 var row = $('#tt').datagrid('getSelected');

     if (row){
       var id=row.id;
                    $.ajax({
                    type:"post",
                    dataType:"json",
                      url:"del_category",
                    data:{id:id},
                    success:function(msg){
                     // alert(msg.status);
                        if(msg.status=="success"){

                           $('#tt').treegrid('reload');

                        }else{
                          alert("不好了什么事情出错了");
                        }
                    }
                  });
         }else{
             alert("你还没有选择一条记录");
         }
  }

function save(){
  var parent=$("#parent").val();
  var name=$("#name").val();
 
  $.ajax({
  type:"post",
  dataType:"json",
    url:"save_category",
  data:{'parent':parent,'name':name},
  success:function(msg){
   // alert(msg.status);
      if(msg.status=="success"){
        $("#parent").val('');
        $("#name").val('');
       
         $('#tt').treegrid('reload');
         $('#w').window('close');
      }else{
        alert("不好了出错了！");
      }
  }
});

}


function save_edit(){
  var edid=$("#edid").val();
  var edname=$("#edname").val();
  
 
  $.ajax({
  type:"post",
  dataType:"json",
    url:"save_edit_category",
  data:{'id':edid,'name':edname},
  success:function(msg){
   // alert(msg.status);
      if(msg.status=="success"){

         $('#tt').treegrid('reload');
         $('#edit').window('close');
      }else{
        alert("不好了出错了！");
      }
  }
});

}



</script>
</head>
<body>
  <h2 class="navfont">员工分类管理:</h2>
   

   <div id="toolbar">
    <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="add()">新增</a>
    <a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="edit()">编辑</a>
    <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="del()">删除</a>
  </div>
  <table title="" id="tt" toolbar="#toolbar" class="easyui-treegrid" style="width:1100px;height:400px"
      data-options="
        url: '<?php  echo site_url();?>index.php/employeecate/get_category',
        method: 'get',
        rownumbers: true,
        idField: 'id',
        treeField: 'name'
      ">
    <thead>
      <tr>
        <th data-options="field:'name'" width="220">分类名称</th>
       
      </tr>
    </thead>
  </table>


  <div id="w" class="easyui-dialog" style="width:800px;height:350px;padding:10px 20px"
      closed="true" buttons="#dlg-buttons">

 <form id="J_Form" class="form-horizontal" action="">

    <div class="row">
      <div class="control-group span8">
            <label class="control-label"><s>*</s>上级分类</label>
            <div class="controls">
            <input type="hidden" name="parent" id="parent" value="">
              <input name="" id="father" type="text" disabled="disabled" value="" data-rules="{required:true}" class="input-normal control-text">
            </div>
          </div>
          <div class="control-group span8">
            <label class="control-label"><s>*</s>分类名称</label>
            <div class="controls">
              <input name="name" id="name" type="text" data-rules="{required:true}" class="input-normal control-text">
            </div>
          </div>
          
        </div>

       

      </form>

  </div>

 <div id="edit" class="easyui-dialog" style="width:800px;height:350px;padding:10px 20px"
      closed="true" buttons="#dlg-edit-buttons">

 <form id="J_Form" class="form-horizontal" action="">

    <div class="row">

          <div class="control-group span8">
            <label class="control-label"><s>*</s>分类名称</label>
            <div class="controls">
            <input type="hidden" id="edid" value="">
              <input name="name" id="edname" type="text" data-rules="{required:true}" class="input-normal control-text">
            </div>
          </div>
          
        </div>

       

      </form>

  </div>


<div id="dlg-buttons">
    <a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="save()">保存</a>
    <a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#w').dialog('close')">取消</a>
  </div>
<div id="dlg-edit-buttons">
    <a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="save_edit()">保存</a>
    <a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#edit').dialog('close')">取消</a>
  </div>
</body>
</html>